use Untappd;

open (MYFILE, '>>data_new1.csv');

my $untappd = Untappd->new({
   client_id     => "019FE8B51CDD97BB2B1929768AF736453F9C5A58",
   client_secret => "57AAC4C13BA60D042D7703AB6EE40A547331A5E0",
});


my $beers = $untappd->search_beer({ q => "Mother Earth Brew Company" });

foreach my $beer ( @{ $beers->{beers}{items} } ) {
	print MYFILE "$beer->{beer}{bid},";
    print MYFILE "$beer->{beer}{beer_name},";
    print MYFILE "Mother Earth Brew Company,\n"
}

my $beers = $untappd->search_beer({ q => "Russian River Brewing Company" });

foreach my $beer ( @{ $beers->{beers}{items} } ) {
	print MYFILE "$beer->{beer}{bid},";
    print MYFILE "$beer->{beer}{beer_name},";
    print MYFILE "Russian River Brewing Company,\n"
}

my $beers = $untappd->search_beer({ q => "Heavy Seas Beer" });

foreach my $beer ( @{ $beers->{beers}{items} } ) {
	print MYFILE "$beer->{beer}{bid},";
    print MYFILE "$beer->{beer}{beer_name},";
    print MYFILE "Heavy Seas Beer,\n"
}

my $beers = $untappd->search_beer({ q => "Bowser Brewing Company" });

foreach my $beer ( @{ $beers->{beers}{items} } ) {
	print MYFILE "$beer->{beer}{bid},";
    print MYFILE "$beer->{beer}{beer_name},";
    print MYFILE "Bowser Brewing Company,\n"
}

my $beers = $untappd->search_beer({ q => "Silver Moon Brewing" });

foreach my $beer ( @{ $beers->{beers}{items} } ) {
	print MYFILE "$beer->{beer}{bid},";
    print MYFILE "$beer->{beer}{beer_name},";
    print MYFILE "Silver Moon Brewing,\n"
}

my $beers = $untappd->search_beer({ q => "Lonerider Brewing Company" });

foreach my $beer ( @{ $beers->{beers}{items} } ) {
	print MYFILE "$beer->{beer}{bid},";
    print MYFILE "$beer->{beer}{beer_name},";
    print MYFILE "Lonerider Brewing Company,\n"
}

my $beers = $untappd->search_beer({ q => "Ithaca Beer Company" });

foreach my $beer ( @{ $beers->{beers}{items} } ) {
	print MYFILE "$beer->{beer}{bid},";
    print MYFILE "$beer->{beer}{beer_name},";
    print MYFILE "Ithaca Beer Company,\n"
}

close (MYFILE); 

#my $beer = $untappd->beer_info({ bid => "9681" });

#print "$beer->{beer}{beer_name} by $beer->{beer}{brewery}{brewery_name} ",
#      "in $beer->{beer}{brewery}{location}{brewery_city}, ",
#      "$beer->{beer}{brewery}{location}{brewery_state} ",
#      "rated $beer->{beer}{rating_score}\n ";